package com.tangyuan.live.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tangyuan.live.entity.dto.LiveQueryDto;
import com.tangyuan.common.result.Result;
import com.tangyuan.live.entity.dto.LiveSaveDto;
import com.tangyuan.live.entity.vo.*;
import com.tangyuan.live.service.LiveRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("live/room")
@RestController
public class LiveRoomController {

    @Autowired
    LiveRoomService liveRoomService;

    /**
     * 获取正在直播的直播记录
     * @param dto 查询DTO
     * @return 直播记录
     */
    @GetMapping("getLiveRoomList")
    public Result<Page<LiveRoomListVo>> getLiveRoomList(@ModelAttribute LiveQueryDto dto){
        return Result.ok(liveRoomService.getLiveRoomList(dto));
    }

    /**
     * 获取我的直播记录
     * @param userId 用户ID
     * @param dto 查询条件
     * @return 我的直播记录
     */
    @GetMapping("getMyLiveList")
    public Result<Page<MyLiveVo>> getMyLiveList(@RequestHeader Long userId,
                                                @ModelAttribute LiveQueryDto dto){
        return Result.ok(liveRoomService.getMyLiveList(userId,dto));
    }

    /**
     * 创建直播
     * @param userId 用户ID
     * @param dto 参数
     * @return 直播数据
     */
    @PostMapping("createLiveRoom")
    public Result<LiveRoomVo> createLiveRoom(@RequestHeader Long userId,
                                             @RequestBody LiveSaveDto dto){
        return liveRoomService.createLiveRoom(userId,dto);
    }

    /**
     * 结束直播
     * @param userId 用户Id
     * @param roomId 房间Id
     * @return MyLiveVo
     */
    @PostMapping("endLive")
    public Result<EndLiveVo> endLive(@RequestHeader Long userId,
                                     @RequestParam Long roomId){
        return liveRoomService.endLive(userId,roomId);
    }

    /**
     * 生成UserSig
     * @param userId 用户Id
     * @return MyLiveVo
     */
    @GetMapping("generateUserSig")
    public Result<String> generateUserSig(@RequestHeader Long userId){
        return Result.ok(liveRoomService.generateUserSig(userId));
    }

    /**
     * 获取用户的直播信息
     * @param userId 用户Id
     * @param liveUserId 搜索用户ID
     * @param roomId 房间Id
     * @return LiveUserMsgVo
     */
    @GetMapping("getLiveUserMsg")
    public Result<LiveUserMsgVo> getLiveUserMsg(@RequestHeader Long userId,
                                                @RequestParam Long liveUserId,
                                                @RequestParam Long roomId){
        return liveRoomService.getLiveUserMsg(userId,liveUserId,roomId);
    }


}
